package com.ruoyi.app.service.impl;

import com.ruoyi.app.domain.User;
import com.ruoyi.app.mapper.UserMapper;
import com.ruoyi.app.service.IUserService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * x用户Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@Service
public class UserServiceImpl implements IUserService
{
    @Autowired
    private UserMapper userMapper;

    @Override
    public AjaxResult reight(User user) {
        User user1 = userMapper.login(user.getPhone());
        if(user1==null){
            return userMapper.reight(user);
        }
        user.setAvatar("http://sw771v73v.hb-bkt.clouddn.com/"+user1.getAvatar());
        return AjaxResult.error("用户已存在");
    }

    @Override
    public String login(User user) {
        User login = userMapper.login(user.getPhone());
        if(login!=null){
            return login.getPhone();
        }
        return "登陆失败";
    }

    @Override
    public User getById(String phone) {
        return userMapper.getById(phone);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public User getName(Long userId) {
        return userMapper.getName(userId);
    }
}
